package com.ruoyi.assemble.fastloader.model;

import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 文件模型
 * @author 洋葱骑士
 *
 */
@Data
public class TFileInfo implements Serializable {

	private static final long serialVersionUID = 6969462437970901728L;

    public static final int ONE_ZERO_TWO_FOUR = 1024;

    /**
     * 附件编号
     */
	private String id;

    /**
     * 附件名称
     */
    private String filename;

    private String nameSearch;

    /**
     * 附件MD5标识
     */
    private String identifier;

    /**
     * 附件总大小
     */
    private Long totalSize;

    private String totalSizeName;

    /**
     * 附件类型
     */
    private String type;

    /**
     * 附件存储地址
     */
    private String location;

    /**
     * EGRID FILE PATH
     */
	private String egridFile;

    /**
     * 删除标志
     */
    private String delFlag;

    /**
     * 文件所属目标（项目、学生、档案等，预留字段）
     */
    private String refProjectId;

    /**
     * 上传人
     */
    private String uploadBy;

    /**
     * 上传时间
     */
    private Date uploadTime;

    /**
     * 上传时间-str
     */
    private String uploadTimeString;

    /**
     * 解压zip标志 0未解压 1已解压
     */
	private String unzipFlag;
    /**
     * 解压zip日志
     */
	private String unzipLog;
    /**
     * 文件后缀
     */
	private String fileSuffix;

    public void setTotalSize(Long totalSize) {
        this.totalSize = totalSize;
        if(ONE_ZERO_TWO_FOUR*ONE_ZERO_TWO_FOUR > this.totalSize && this.totalSize >= ONE_ZERO_TWO_FOUR ) {
            this.totalSizeName = String.format("%.2f",this.totalSize.doubleValue()/ONE_ZERO_TWO_FOUR) + "KB";
        }else if(ONE_ZERO_TWO_FOUR*ONE_ZERO_TWO_FOUR*ONE_ZERO_TWO_FOUR > this.totalSize && this.totalSize >= ONE_ZERO_TWO_FOUR*ONE_ZERO_TWO_FOUR ) {
            this.totalSizeName = String.format("%.2f",this.totalSize.doubleValue()/(ONE_ZERO_TWO_FOUR*ONE_ZERO_TWO_FOUR)) + "MB";
        }else if(this.totalSize >= ONE_ZERO_TWO_FOUR*ONE_ZERO_TWO_FOUR*ONE_ZERO_TWO_FOUR ) {
            this.totalSizeName = String.format("%.2f",this.totalSize.doubleValue()/(ONE_ZERO_TWO_FOUR*ONE_ZERO_TWO_FOUR*ONE_ZERO_TWO_FOUR)) + "GB";
        }else {
            this.totalSizeName = this.totalSize.toString() + "B";
        }
    }
}
